﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using BusinessIntelligenceToolkit.Controls;
using BusinessIntelligenceToolkit.Framework.Extensions;

namespace BusinessIntelligenceToolkit.Demo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly WeatherForecastViewModel _weatherForecastViewModele = new WeatherForecastViewModel();

        public MainWindow()
        {
            InitializeComponent();

            DataContext = _weatherForecastViewModele;
        }

        private void OnRefreshClick(object sender, RoutedEventArgs e)
        {
            tbCreatedContainers.Text = bitListBox.FindChild<BitStackPanel>("PART_ItemsHost").Children.Count.ToString();
        }

        private void OnAnimationApplyClick(object sender, RoutedEventArgs e)
        {
            DoubleAnimation animation = new DoubleAnimation();
            animation.Duration = new Duration(TimeSpan.FromSeconds(slider.Value));
            string selectedAnimationKey = (cbAnimation.SelectedItem as ComboBoxItem).Content.ToString();
            EasingFunctionBase easingFunctionBase = null;
            switch (selectedAnimationKey)
            {
                case "None":
                    bitListBox.Animation = null;
                    return;
                case "Back":
                    easingFunctionBase = new BackEase();
                    break;
                case "Bounce":
                    easingFunctionBase = new BounceEase();
                    break;
                case "Circle":
                    easingFunctionBase = new CircleEase();
                    break;
                case "Cubic":
                    easingFunctionBase = new CubicEase();
                    break;
                case "Elastic":
                    easingFunctionBase = new ElasticEase();
                    break;
                case "Exponential":
                    easingFunctionBase = new ExponentialEase();
                    break;
                case "Power":
                    easingFunctionBase = new PowerEase();
                    break;
                case "Quadratic":
                    easingFunctionBase = new QuadraticEase();
                    break;
                case "Quartic":
                    easingFunctionBase = new QuarticEase();
                    break;
                case "Quintic":
                    easingFunctionBase = new QuinticEase();
                    break;
                case "Sine":
                    easingFunctionBase = new SineEase();
                    break;
            }
            easingFunctionBase.EasingMode = (EasingMode)new [] { rbIn, rbOut, rbInOut }.First(rb => rb.IsChecked.Value).Tag;
            animation.EasingFunction = easingFunctionBase;
            bitListBox.Animation = animation;
        }
    }
}
